<template>
  <BasicModal v-bind="$attrs" @register="register" showFooter :title="getTitle" width="70%" @ok="handleSubmit"
    :okButtonProps="{ loading }">

    <BasicForm @register="registerForm" />


  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, h, toRaw, reactive } from 'vue';
import { BasicForm, useForm } from '@/components/Form';
import {
  BasicTableProps,
  VxeBasicTable,
  VxeGridInstance,
  VxeGridListeners,
  VxeTableDefines,
} from '@/components/VxeTable';

import {
  componentColumns, labelColumns,
  formSchema,

} from './role.data';

import { BasicModal, useModalInner } from '@/components/Modal';


import { orderEdit, orderEditAdd, } from '@/api/heng/dkn';


import { useMessage } from "@/hooks/web/useMessage";
import util from '@/utils/util';

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const { createMessage } = useMessage();

const orderCode = ref("");
const dataList = ref({});
const loading = ref(false);

const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
  labelWidth: 100,
  schemas: formSchema,
  showActionButtonGroup: false,
  baseColProps: { lg: 12, md: 24 },
});

const tableRef = ref<VxeGridInstance>();

const gridOptions = reactive<BasicTableProps>({
  // keepSource: true,
  editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  border: true,
  showOverflow: true,
  keepSource: true,
  size: 'mini',
  height: 'auto', // 'auto'
  columns: componentColumns,
  filterConfig: {
    remote: true,
  },
  exportConfig: {},
  toolbarConfig: {
    slots: {
      buttons: 'toolbar_buttons',
    },
    refresh: true,
  },
  formConfig: {
    enabled: false,
  },
  pagerConfig: {
    enabled: false,
  },
  proxyConfig: {
    enabled: false,

  },
});



const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //打开弹层后的回调
  // resetFields();
  setModalProps({ confirmLoading: false });
  //dataList.value = data.record;
  orderCode.value = data.record.orderCode;
  isUpdate.value = data.isUpdate;
  setFieldsValue(data.record);

});

const getTitle = computed(() => ('修改商品信息'));


//async function handleSubmit()

async function handleSubmit() {
  try {
    loading.value = true;

    const values = await validate();
    values.orderCode = orderCode.value;
    orderEdit(values).then(res => {
      sunccFn(res)
    }).finally(() => {
      loading.value = false;
      setModalProps({ confirmLoading: false });

    });
  } catch (e) {
    console.log(e)
  }
}

function sunccFn(result) {
  if (result && result.code == 200) {
    createMessage.success(result.message);
  } else {
    createMessage.error(result.message);
  }
  closeModal()
  emit('success');
}

function cancelFn() {
  //  tableRef.value.clearValidate();
}



</script>
<style lang="less">
.item-row {
  margin: 0 auto;

  //padding-left: 5%;
  .ant-form-item-label {
    flex: 0 0 28.5%;
    max-width: 28.5%;
  }
}

.lqfp-8 {
  //padding-left: 9% !important;

}
</style>
